home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_09 / 1109090a < prev    next >
Text File  |  1993-07-06  |  1KB  |  34 lines

  1. typedef  struct resdesc
  2. {
  3.         float out1, out2;   /* filter state variables */
  4.         float a1, b1, b2;   /* filter coefficients */
  5. } resdesc;
  6. static void Avoid_Underflow(resdesc *o)
  7. {
  8.         /* clamp state variables */
  9.         if(o->out1>-0.0000000001f 
  10.                         && o->out1<0.0000000001f)
  11.                 o->out1 = 0.0f;
  12.         if(o->out2>-0.0000000001f 
  13.                         && o->out2<0.0000000001f)
  14.                 o->out2 = 0.0f;
  15. }
  16. /* assumes coefficients are constant throughout block */
  17. void Resonator(resdesc *f , int n,   float *out,
  18.                int stride,  float *in, int istride )
  19. {
  20.          float ym;
  21.          int j;
  22.         
  23.         j=0;
  24.         for(j=0;j<n;++j)
  25.         {
  26.                 ym = f->b1 * f->out1 + f->b2 * f->out2
  27.                          + f->a1 * in[j*istride];       
  28.                 f->out2 = f->out1;      
  29.                 f->out1 = ym;
  30.                 out[j*stride] = ym;
  31.         }
  32.         Avoid_Underflow(f);     
  33. }
  34.